package com.kyub.spring.gears.services;

import com.kyub.spring.gears.model.FileLayout;

import java.io.IOException;
import java.io.Serializable;

/**
 * FileStorageService is the inteface you have to implement to provide custom behavior for persisting files
 */
public interface FileStorageService {

    /**
     * @param url of the file from the pojo
     * @return byte of the loaded file
     * @throws IOException if something goes wrong
     */
    public byte[] load(String url) throws IOException;

    /**
     * Save the file
     *
     * @param pojoName         name of the pojo thath owns the attachment
     * @param id               can be null
     * @param propertyName     name of the property that holds the url in the pojo
     * @param fileLayout       full metadata structure of the property that holds the url in the pojo
     * @param originalFilename of the uploaded file
     * @param payload          file content
     * @throws IOException if something goes wrong
     */
    public void save(String pojoName, Serializable id, String propertyName, FileLayout fileLayout, String originalFilename, byte[] payload) throws IOException;


}
